package com.itheima.dao;

import com.itheima.pojo.Menu;
import com.itheima.pojo.Permission;
import com.itheima.pojo.Role;
import com.itheima.pojo.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

@Mapper
public interface UserDao {

    @Select("select * from t_user where username = #{username}")
    User findByUsername(String username);

    @Select("SELECT r.*  FROM t_user_role ur LEFT JOIN t_role r ON r.id = ur.role_id  WHERE ur.user_id = #{id}")
    List<Role> loadRolesByUserId(Integer id);


    @Select("SELECT p.* FROM t_role_permission rp LEFT JOIN t_permission p ON p.id = rp.permission_id  WHERE rp.role_id = #{id}")
    Set<Permission> getPermissions(Integer id);

    @Select("SELECT m.* FROM t_role_menu rm LEFT JOIN t_menu m ON m.id = rm.menu_id  WHERE rm.role_id = #{id}")
    LinkedHashSet<Menu> getMenus(Integer id);
}
